<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Db;
use think\Validate;


/**
 * 获取进校预约
 * Class Entryapply
 * @package app\api\controller
 */
class Entryapply extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }


    public function index()
    {
        $wids = Db::name('entryapply') -> column('wid');
        $inArr = [];
        foreach ($wids as $k => &$v){
            $v = "'$v'";
            $inArr[intval($k/999)][] = $v;
        }

        $instrArr = [];
        foreach ($inArr as $idarr){
            $instrArr[] = " WID not in (".implode(',',$idarr).") ";
        }


        $instr = implode(' and ',$instrArr);


        $dbconn = \oci_connect('usr_yqsb','Qdnydx_wis_2020',"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.8.16.19)(PORT=1521))(CONNECT_DATA=(SID=ZHFWDB)))","UTF8");
        if ($dbconn) {
//            echo '连接成功';
        }else {
//            echo '连接失败';
        }

        $sql="select * from  yqsb where $instr";

        $stmt=oci_parse($dbconn,$sql);
        oci_execute($stmt);
        $result=oci_fetch_all($stmt,$dw);
//        var_dump($result);
//        var_dump($dw);
//
//
//        exit;
        if($result > 0){
            $data = [];
            for ($i = 0; $i < $result; $i++) {
                foreach ($dw as $key => $value) {
                    if($key == 'QSTIME'){
                        $data[$i][strtolower($key)] = date('Y-m-d',strtotime($value[$i]));
                    }else{
                        $data[$i][strtolower($key)] = $value[$i];
                    }
                }
            }
//            print_r($data);
            Db::name('entryapply') -> insertAll($data);
        }

    }

    public function all(){

        $dbconn = \oci_connect('usr_yqsb','Qdnydx_wis_2020',"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.8.16.19)(PORT=1521))(CONNECT_DATA=(SID=ZHFWDB)))","UTF8");
        if ($dbconn) {
//            echo '连接成功';
        }else {
//            echo '连接失败';
        }

        $sql="select * from  yqsb";

        $stmt=oci_parse($dbconn,$sql);
        oci_execute($stmt);
        $result=oci_fetch_all($stmt,$dw);
//        var_dump($result);
//        var_dump($dw);
//
//
//        exit;
        $str = "<table>";
        if($result > 0){
            $data = [];
            for ($i = 0; $i < $result; $i++) {
                $str .= "<tr>";
                foreach ($dw as $key => $value) {
                    if($key == 'QSTIME'){
                        $data[$i][strtolower($key)] = date('Y-m-d',strtotime($value[$i]));
                        $tim = date('Y-m-d',strtotime($value[$i]));
                        $str .= "<td>$tim</td>";
                    }else{
                        $data[$i][strtolower($key)] = $value[$i];
                        $str .= "<td>{$value[$i]}</td>";
                    }

                }
                $str .= "</tr>";
            }
        }
        $str .= "</table>";
        echo $str;
    }
}